// Separator for navigation items
@mixin nav-item-separator {
    border-bottom: 1px solid $border-grey;
}

#navigation-topheader {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    z-index: 21;
    box-shadow: -2px 2px 4px -2px rgba(0, 0, 0, .8);
    background-color: #424242;
    padding: 0 $main-padding 0 (2 * $main-padding);
    min-height: 68px;
    color: #ffffff;

    .my-identity {
        flex-grow: 1;
        width: 85%;

        span {
            display: inline-block;
            cursor: pointer;
            max-width: 100%;
            overflow: hidden;
            text-shadow: .5px .5px 1px rgba(0, 0, 0, .25);
            text-overflow: ellipsis;
            white-space: nowrap;
            font-size: 16pt;
            word-wrap: break-word;
            word-break: break-all;
        }
    }
}

#navigation-header {
    z-index: 18;
    box-shadow: -2px 2px 4px -2px rgba(0, 0, 0, .4);
    background-color: #f5f5f5;

    .main {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;

        .md-nav-item {
            :first-of-type {
                margin-left: 0;
            }
        }

        .md-button {
            min-width: 42px;
        }
    }

    .search {
        $duration-opacity: .1s;
        $duration-height: .2s;
        transition: opacity $duration-opacity linear,
        max-height $duration-height ease-out $duration-opacity,
        visibility 0s linear $duration-height;
        visibility: hidden;
        opacity: 0;
        // Animation when disappearing
        max-height: 0;

        input {
            &[type='search'] {
                margin: 0;
                border: 1px solid #dddddd;
                border-radius: $material-radius;
                background-color: #ffffff;
                padding: $main-padding;
                width: 100%;
                box-sizing: border-box;
            }
        }

        &.visible {
            transition: visibility 0s,
            max-height $duration-height ease-in,
            opacity $duration-opacity linear $duration-height;
            visibility: visible;
            opacity: 1;
            padding: $main-padding;

            // Animation when appearing
            max-height: 50px;

            ::-webkit-search-cancel-button {
                -webkit-appearance: searchfield-cancel-button;
            }
        }
    }
}

#navigation-conversations,
#navigation-contacts {
    @include scrollbar;

    .empty {
        margin-top: 1em;
        margin-left: 16px;
        color: $material-grey;
        font-size: 1.2em;
        font-weight: 300;
    }
}

#navigation-conversations {
    $border-width: 4px;
    $border-count: 2;
    flex: 1;
    background-color: #ffffff;
    overflow-y: auto;

    .loading-element {
        margin-top: 50px;
    }

    .conversation-wrapper {
        @include nav-item-separator;
        display: block;

        .conversation {
            display: flex;
            flex-direction: row;
            align-items: center;
            border-left: $border-width * $border-count solid #ffffff;
            padding: (1.5 * $main-padding) $main-padding - ($border-width * ($border-count - 1));

            &.active,
            &:hover {
                border-color: $dark-background-color;
                background-color: $dark-background-color;
            }

            &:hover {
                &:not(.active) {
                    cursor: pointer;
                }
            }

            // Only unread
            &.unread {
                border-image: linear-gradient(
                    to right,
                    $status-error,
                    $status-error 50%,
                    #ffffff 50%,
                    #ffffff 100%
                ) 1 100%;

                &.active {
                    border-image: linear-gradient(
                        to right,
                        $status-error,
                        $status-error 50%,
                        $dark-background-color 50%,
                        $dark-background-color 100%
                    ) 1 100%;
                }
            }

            // Only starred
            &.starred {
                border-image: linear-gradient(
                    to right,
                    $status-starred,
                    $status-starred 50%,
                    #ffffff 50%,
                    #ffffff 100%
                ) 1 100%;

                &.active {
                    border-image: linear-gradient(
                        to right,
                        $status-starred,
                        $status-starred 50%,
                        $dark-background-color 50%,
                        $dark-background-color 100%
                    ) 1 100%;
                }
            }

            // Both starred and unread
            &.starred.unread {
                border-image: linear-gradient(
                    to right,
                    $status-error,
                    $status-error 50%,
                    $status-starred 50%,
                    $status-starred 100%
                ) 1 100%;
            }

            .avatar-box {
                position: relative;
                margin-right: 8px;

                .loading {
                    position: absolute;
                }
            }

            .conversation-box {
                display: flex;
                flex-direction: column;
                flex-grow: 1;
                overflow: hidden;

                .receiver-box,
                .message-box {
                    flex-wrap: nowrap;
                    line-height: 1.4em;

                }

                .receiver-box {
                    display: flex;
                    flex-direction: row;
                    flex-grow: 1;
                    justify-content: space-between;
                    color: #000000;
                    font-weight: bold;

                    .title {
                        flex: 1;
                        margin-right: $main-padding;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                    }

                    .disabled {
                        text-decoration: line-through;
                    }

                    .notification-settings {
                        margin: 1px 0 0 4px;
                        padding: 0;
                        height: 20px;
                    }
                }

                .message-box {
                    flex-grow: 1;

                    .latest-message {
                        display: flex;
                        flex-direction: row;
                        align-items: center;
                        justify-content: space-between;
                        color: $material-grey;

                        .left {
                            display: flex;
                            overflow: hidden;
                            text-overflow: ellipsis;
                            white-space: nowrap;

                        }

                        .right {
                            flex-shrink: 0;
                            margin-left: 24px;
                            text-align: right;

                            .draft {
                                color: #c62828;
                            }
                        }

                        .message-name,
                        .message-text {
                            line-height: 1.7em;
                        }

                        .message-name {
                            &::after {
                                margin-right: 4px;
                                content: ':';
                            }
                        }

                        .message-text {
                            overflow: hidden;
                            text-overflow: ellipsis;
                            white-space: nowrap;
                        }

                        &.is-hidden {
                            .no-hidden {
                                display: none;
                            }
                        }

                        &.is-typing {
                            .no-typing {
                                display: none;
                            }
                        }

                        &.show-draft {
                            .no-draft {
                                display: none;
                            }
                        }

                        &:not(.is-typing) {
                            .typing {
                                display: none;
                            }
                        }

                        &:not(.show-draft) {
                            .draft {
                                display: none;
                            }
                        }

                        &:not(.is-hidden) {
                            .hidden {
                                display: none;
                            }
                        }
                    }
                }
            }

            .badge.unread-count {
                margin-left: 4px;
                border-radius: 5px;
                background-color: $status-error;
                padding: 0 5px;
                color: #ffffff;
                font-size: .9em;
            }
        }
    }
}

#navigation-contacts {
    flex: 1;
    overflow-y: scroll;

    .contact {
        @include nav-item-separator;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        border-left: 4px solid #ffffff;
        padding: 12px 8px;

        .avatar-box {
            padding-right: 8px;
        }

        .left {
            display: flex;
            flex-direction: column;
            flex-grow: 1;
        }

        .right {
            display: flex;
            flex-direction: column;
            align-items: flex-end;
        }

        .name {
            font-weight: bold;
        }

        .nickname {
            font-size: .8em;
        }

        &:hover {
            background-color: #f5f5f5;
            cursor: pointer;
        }
    }

    .contact.inactive {
        opacity: .5;
    }

    .hide-inactive .contact.inactive,
    .hide-inactive .contact.invalid {
        display: none;
    }
}

#navigation-fab {
    position: relative;

    md-icon {
        color: #ffffff;
    }

    .fab-button-add-contact {
        background-color: #d32f2f;
    }

    .fab-button-add-group {
        background-color: #ff9800;
    }

    .fab-button-add-distribution-list {
        background-color: #3f51b5;
    }
}
